<template>
  <header class="header">
    <h1>todos</h1>
    <input id="toggle-all" class="toggle-all" type="checkbox" v-model="isAll">
    <label for="toggle-all"></label>
    <input
      class="new-todo"
      placeholder="输入任务名称-回车确认"
      autofocus
      @keydown.enter="enterDown"
      v-model.trim="val"
    />
  </header>
</template>

<script>
export default {
 name:'TodoHeader',
 props:['list'],
 data(){
     return{
         val:''
     }
 },
 methods:{
     enterDown(){
           if(!this.val){
               return alert('还没有输入内容呢！')
           }
            this.$emit('add',this.val)
            // 清空文本框
            this.val=''
     },
 },
    computed:{
        isAll:{
            set(checked){
               return  this.list.forEach(ele=>ele.isDone=checked)
            },
            get(){
                return this.list.length !==0 && this.list.every(ele=>ele.isDone===true)
            }
        }
    }
}
</script>